package com.lyf.shop.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * @ClassName DateUtil
 * @Description TODO
 * @Author cos
 * @Date DATE:上午 10:12
 */
public class DateUtil {
    private static final SimpleDateFormat[] sdf = new SimpleDateFormat[3];

    static{
        sdf[0]=new SimpleDateFormat("yyyy-MM-dd");
        sdf[1]=new SimpleDateFormat("yyyy/MM/dd");
        sdf[2]=new SimpleDateFormat("yyyy年MM月dd日");
    }

    /**
     * 字符串转日其
     * @param date
     * @return
     */
    public static java.util.Date stringToDate(String date){
        java.util.Date d = null;
        for (int i = 0; i < sdf.length; i++) {
            try {
                d = sdf[i].parse(date);
                break;
            } catch (ParseException e) {
                continue;
            }
        }
        return d;
    }

    /**
     * 日期转字符串
     * @param date
     * @return
     */
    public static String dateToString(java.util.Date date){
        return sdf[0].format(date);
    }

    /**
     * utildate转为sqldate
     * @param date
     * @return
     */
    public static java.sql.Date utilDateToSqlDate(java.util.Date date){
        return new java.sql.Date(date.getTime());
    }



}
